﻿using Ewelve_Mouth_HD.BLL;
using Ewelve_Mouth_HD.DAL;
using Ewelve_Mouth_HD.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Ewelve_Mouth_HD.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class NubController : ControllerBase
    {
        private readonly NubBll nubBll;
        private readonly ILogger<NubController> _logger;

        public NubController(NubBll _nubBll, ILogger<NubController> logger)
        {
            nubBll = _nubBll;
            _logger = logger;
        }
        /// <summary>
        /// 房号添加
        /// </summary>
        /// <param name="E"></param>
        /// <returns></returns>
        [HttpPost]
        public int NubAdd(RoomNub E)
        {
            try
            {
                return nubBll.NubAdd(E);
            }
            catch (Exception)
            {
                _logger.LogInformation("房号添加错误");
                throw;
            }
        }
        /// <summary>
        /// 查询显示房号
        /// </summary>
        /// <param name="NubCard"></param>
        /// <param name="TypeName"></param>
        /// <param name="StartDate"></param>
        /// <param name="EndDate"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult RoomNubShow(string? NubCard, int TypeName, DateTime? StartDate, DateTime? EndDate)
        {
            try
            {
                var list= nubBll.RoomNubShow(NubCard, TypeName, StartDate, EndDate);
                return Ok(new { list=list});
            }
            catch (Exception)
            {
                _logger.LogInformation("房号显示错误");
                throw;
            }
        }
        /// <summary>
        /// 查询单个数据
        /// </summary>
        /// <param name="NubId"></param>
        /// <returns></returns>
        [HttpGet]
        public RoomNub FirstOnly(int NubId)
        {
            try
            {
                return nubBll.FirstOnly(NubId);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="NubId"></param>
        /// <returns></returns>
        [HttpDelete]
        public int DropNup(int NubId)
        {
            try
            {
                return nubBll.DropNup(NubId);
            }
            catch (Exception)
            {
                _logger.LogInformation("房号删除错误");
                throw;
            }
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="NubId"></param>
        /// <param name="NubStage"></param>
        /// <returns></returns>
        [HttpPut]
        public int EditStage(int NubId, int NubStage)
        {
            try
            {
                return nubBll.EditStage(NubId, NubStage);
            }
            catch (Exception)
            {
                _logger.LogInformation("房号修改错误");
                throw;
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="Y"></param>
        /// <returns></returns>
        [HttpPut]
        public int EditNub(RoomNub Y)
        {
            try
            {
                return nubBll.EditNub(Y);
            }
            catch (Exception)
            {
                _logger.LogInformation("房号修改错误");
                throw;
            }
        }
        /// <summary>
        /// 批量逻辑删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public int SumDrop(string ids)
        {
            try
            {
                return nubBll.SumDrop(ids);
            }
            catch (Exception)
            {
                _logger.LogInformation("房号删除错误");
                throw;
            }
        }
        /// <summary>
        /// 批量修改状态
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="NubStage"></param>
        /// <returns></returns>
        [HttpPut]
        public int SumEditSatage(string ids, int NubStage)
        {
            try
            {
                return nubBll.SumEditSatage(ids, NubStage);
            }
            catch (Exception)
            {
                _logger.LogInformation("房号修改错误");
                throw;
            }
        }
        /// <summary>
        /// 绑定下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IQueryable NubShow()
        {
            try
            {
                return nubBll.NubShow();
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
